#__*__coeding:utf-8__*__
#!/usr/share/python
'''
---------------------------------------------------------------- 
 版权所有。  
 
 文件名：
 文件功能描述： 
 author：
 时间：
--------------------------------------------------------------- 
'''


from flask import Flask

from DB.useranalysisdb import data_insert
from logdispose.logfiledispose import log_dispose
from logdispose.logfiledatenalysis import UserAnalysis

log=Flask(__name__)

class LogDispoesServer:

    def __init__(self,file_name):
        self.logobj=log_dispose()
        self.file_name=file_name
        self.dispose_log=self.logobj.baselogdispose(self.file_name)
        if self.dispose_log is None:
            log.logger.critical(self.dispose_log)
            pass
        else:
            self.UserAnalysis=UserAnalysis
            self.all_or_date=self.UserAnalysis.all_or_date(self.UserAnalysis,self.dispose_log)
            self.accsee_ip=self.UserAnalysis.accsee_ip(self.UserAnalysis,self.dispose_log)
            self.Access_time=self.UserAnalysis.Access_time(self.UserAnalysis,self.dispose_log)
            self.Access_referer_addr=self.UserAnalysis.Access_referer_addr(self.UserAnalysis,self.dispose_log)
            self.Access_agent=self.UserAnalysis.Access_agent(self.UserAnalysis,self.dispose_log)
            self.Access_forwarded_for=self.UserAnalysis.Access_forwarded_for(self.UserAnalysis,self.dispose_log)


    def InsertDateAll(self):
        '''
        集中控制插入处理完成的日志数据到数据库
        :return: 插入数据执行结果 《属性：布尔值，True or False》
        '''
        insert = data_insert()
        if self.accsee_ip and self.all_or_date and self.Access_referer_addr and self.Access_forwarded_for and self.Access_agent and self.Access_time != None:
            logdate=insert.insert_allcont_logdate(self.all_or_date)
            log.logger.critical('logdate insert %s' % logdate)
            accsee_ip=insert.insert_ipdata(self.accsee_ip)
            log.logger.critical('accsee_ip insert %s' % accsee_ip)
            Access_time=insert.insert_access_time(self.Access_time)
            log.logger.critical('Access_time insert %s' % Access_time)
            Access_agent=insert.insert_access_agent(self.Access_agent)
            log.logger.critical('Access_agent insert %s' % Access_agent)
            Access_forwarded_for=insert.insert_access_forwarded(self.Access_forwarded_for)
            log.logger.critical('Access_forwarded_for insert %s' % Access_forwarded_for)
            Access_referer_addr=insert.insert_access_referer(self.Access_referer_addr)
            log.logger.critical('Access_referer_addr insert %s' % Access_referer_addr)
            move_file=self.logobj.move_old_file(self.file_name)# 移动文件到已处理目录
            return (logdate,accsee_ip,Access_time,Access_agent,Access_forwarded_for,Access_referer_addr,move_file)
        else:
            return '处理失败,IP归属地为查询次数可能已用完，或其它数据为空！'



